//客户订单列表显示
function clientOrderInfo(){
	var obj = $("#bag").html("");
	obj.load("clientOrderMapping",function(response,status,xhr){
		var data="clientName="+$("#getClientOrderName").val();
		showAllClientOrderInfo(data);
	})
}


//显示客户订单信息
function showAllClientOrderInfo($data){
	var obj=$("#clientOrderTable tbody").html("");
	//获取路径
	var url="/trade-wzj-web/tests/getAllClientOrderInfos";
	//获取参数
	var data=$data;
	//定义字符串拼接
	var str="";
	//调用提交方法
	var result = postMethod(url,"POST",data);
	//获取集合
	var list=result.list;
	
	if(list.length>0){
		for(var i=0;i<list.length;i++){
			str=str+"<tr>" +
						"<td><input type='checkbox' name='clientOrderCheck' value='"+list[i].id+"'></td>"+
						"<td>"+list[i].clientOrderNo+"</td>"+
						"<td>"+list[i].clientQuota.clientInfo.clientName+"</td>"+
						"<td>"+(list[i].deliveryDate-list[i].orderDate)+"</td>"+
						"<td>"+list[i].totalMoney+"</td>"+
						"<td>"+list[i].state.stateInfo+"</td>"+
						"<td style='text-align:center'><a href='#' onclick='selectClientOrderDetail("+list[i].id+");'><span class='glyphicon glyphicon-pencil'></span></a></td>"+
					"</tr>";
			
		}
	}
	
	obj.append(str);
	var page=$("#clientOrderPages").html("");
	//调用分页代码
	var va=getPageClientOrder(result);
	page.append(va);
}


//获取页码信息
function getPageClientOrder($clientList){
	var page="";
	
	var con = $("#getClientOrderName").val();
	page = page+"<div class='row' style='margin:0px'>" +
	"<div class='col-md-2 col-sm-2 col-xs-2' style='padding-top:0.7rem'>"+
		"<span style='font-weight:bold'>总记录数 "+$clientList.total+"   |  总页数 "+$clientList.pages+"</span>"+
	"</div>"+
	"<div class='col-md-offset-8 col-sm-offset-8 col-xs-offset-8'>"
	+"<nav aria-label='Page navigation'>"+
"<ul class='pagination pagination-sm'>";
	if($clientList.prePage>0){
		page = page+"<li><a href='#' onclick='getPagesClientOrder("+$clientList.firstPage+",\""+con+"\")'>首页</a></li>"+
		"<li><a href='#' onclick='getPagesClientOrder("+$clientList.prePage+",\""+con+"\")'>上一页</a></li>";
				
	}
	if($clientList.nextPage<=$clientList.lastPage && $clientList.nextPage>0){
		page = page+"<li><a href='#' onclick='getPagesClientOrder("+$clientList.nextPage+",\""+con+"\")'>下一页</a></li>"+
		"<li><a href='#' onclick='getPagesClientOrder("+$clientList.lastPage+",\""+con+"\")'>末页</a></li>";
	}
	page = page+"</li>"+
"</ul>"+
"</nav>"+
"</div>"+
"</div>";
	return page;
	
}

//分页功能
function getPagesClientOrder($page,$object){
	var data="pages="+$page+"&clientName="+$object;
	showAllClientOrderInfo(data);
}


//按条件查询客户订单
function findClientOrder(){
	//获取查询条件
	var data="pages=&clientName="+$("#getClientOrderName").val();
	//调用显示方法
	showAllClientOrderInfo(data);
}





//全选按钮
function allClientOrders(){
	//点击全选按钮
	var all = document.getElementsByName("allClientOrderName");
	//获取复选框信息
	var other=document.getElementsByName("clientOrderCheck");
	if(all[0].checked==true){
		for(var i=0;i<other.length;i++){
			other[i].checked=true;
		}
	}else{
		for(var i=0;i<other.length;i++){
			other[i].checked=false;
		}
	}
}



var re="";

//生成客户报价单
function getProductId(){
	var tab = $("#addClientOrderPriceTable tbody").html("");
	
	var list = document.getElementsByName("checkProductId");
	var str=[];
	for(var i=0;i<list.length;i++){
		if(list[i].checked){
			str.push(list[i].value);
		}
		
	}
	if(str.length==0){
		alert("请选择产品");
		return;
	}
	
	var url="/trade-wzj-web/tests/kfbjAdd";
	var data=str;
	var resultList = postMethod(url,"POST",data);
	var stTable="";
	var re = resultList.list;
	if(re.length>0){
		for(var i=0;i<re.length;i++){
			stTable=stTable+"<tr>" +
			"<td><input type='hidden' name='clientQuotaDetailsID' value='"+re[i]+"'><input class='form-control' name='' value='"+re[i]+"' /></td>" +
			"<td><input class='form-control' name='productNum' value='"+re[i]+"' /></td>" +
			"<td><input class='form-control' name='' value='"+re[i]+"' /></td>" +
			"<td><input class='form-control' name='' value='"+re[i]+"' /></td>" +
			"<td><input class='form-control' name='quotaPrice' value='"+re[i]+"' /></td>" +
			"<td><input class='form-control' name='quotaMoney' value='"+re[i]+"' /></td>" +
			"<td><input class='form-control'  name='expirationDate' value='"+re[i]+"' /></td>" +
		"</tr>";
		}
		
				
	}
	
	tab.append(str);
	$("#updateClientPriceDetailModal").modal("show");
}

//点击确定按钮
function addClientPricesBtn(){
	var addClientForm = $("#addClientPricesForm").Validform({
		tiptype:1
	});
	
	var bool = addClientForm.check();
	if(bool==false){
		//var vss=$("#contp").html("");
		//window.showModalDialog();
		//$("#dialog").dialog();
		$("#addClientPriceId").popover("toggle");
		return;
	}
	var data = $("#addClientPricesForm").serialize();
	
	//获取提交路径
	var url="/trade-wzj-web/tests/clientquotadetails";
	var res = postMethod(url,"POST",data);
	if(res!=0){
		alert("操作成功!");
	}else{
		alert("操作失败!");
	}
}